package com.yserp.project.erp.order.deliveryorder.controller;

import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.order.deliveryorder.domain.DeliveryOrderItem;
import com.yserp.project.erp.order.deliveryorder.service.IDeliveryOrderItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 发货订单子Controller
 * 
 * @author yserp
 * @date 2022-07-26
 */
@Controller
@RequestMapping("/order/deliveryorder/item")
public class DeliveryOrderItemController extends BaseController
{
    private String prefix = "erp/order/deliveryorder";

    @Autowired
    private IDeliveryOrderItemService deliveryOrderItemService;

    @RequiresPermissions("order:deliveryorder:view")
    @GetMapping()
    public String deliveryorder()
    {
        return prefix + "/deliveryorder";
    }

    /**
     * 查询发货订单子列表
     */
    @RequiresPermissions("order:deliveryorder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DeliveryOrderItem deliveryOrderItem)
    {
        startPage();
        List<DeliveryOrderItem> list = deliveryOrderItemService.selectDeliveryOrderItemList(deliveryOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出发货订单子列表
     */
    @RequiresPermissions("order:deliveryorder:export")
    @Log(title = "发货订单子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DeliveryOrderItem deliveryOrderItem)
    {
        List<DeliveryOrderItem> list = deliveryOrderItemService.selectDeliveryOrderItemList(deliveryOrderItem);
        ExcelUtil<DeliveryOrderItem> util = new ExcelUtil<DeliveryOrderItem>(DeliveryOrderItem.class);
        return util.exportExcel(list, "发货订单子数据");
    }

    /**
     * 新增发货订单子
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存发货订单子
     */
    @RequiresPermissions("order:deliveryorder:add")
    @Log(title = "发货订单子", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DeliveryOrderItem deliveryOrderItem)
    {
        return toAjax(deliveryOrderItemService.save(deliveryOrderItem));
    }

    /**
     * 修改发货订单子
     */
    @RequiresPermissions("order:deliveryorder:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DeliveryOrderItem deliveryOrderItem = deliveryOrderItemService.getById(id);
        mmap.put("deliveryOrderItem", deliveryOrderItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存发货订单子
     */
    @RequiresPermissions("order:deliveryorder:edit")
    @Log(title = "发货订单子", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DeliveryOrderItem deliveryOrderItem)
    {
        return toAjax(deliveryOrderItemService.updateById(deliveryOrderItem));
    }

//    /**
//     * 删除发货订单子
//     */
//    @RequiresPermissions("order:deliveryorder:remove")
//    @Log(title = "发货订单子", businessType = BusinessType.DELETE)
//    @PostMapping( "/remove")
//    @ResponseBody
//    public AjaxResult remove(String ids)
//    {
//        return toAjax(deliveryOrderItemService.removeByIds(Lists.newArrayList(Convert.toLongArray(ids))));
//    }
}
